#ifndef _FreeList_H
#define _FreeList_H

#include <stdio.h>
#include "BadNumberOfBlocksException.h"
#include "CannotReadException.h"

// FIXME: Might need to add headers?
// NOTE from DIANE:  Changed header above.  
//  Assuming we weren't going to add header above
/*#include " "
	""
	""

*/


/* This class represents a special BlockLinkedList called Free List.
 * The Free List keeps track of unused blocks on the Disk device.
 * The Free List can be used to spawn (create) other BlockLinkedList's,
 * assuming there are still free blocks in the Free List. Uses block 0 on the
 * disk as the master block to contain information about the location of the
 * Free List. Cited Doxygen.
*/



class FreeList {
    public:
        // Default number of blocks is 100.
        static const int DEFAULT_NUMBER_OF_BLOCKS = 100;

        //This constructor generates a RAM object representing the free list for the Disk.
        FreeList(Disk *disk, bool createFreeList);

        // Constructor for block
        Block();
        ~Block();
        
        //Writes out the current start block of the free list to block 0.
        //Closes the List.
        bool close();

        //Returns all blocks of the BlockLinkedList to the Free List.
        void Return(BlockLinkedList *bll);

        //Spawn a new BlockGroup from the Free List.
        //The new BlockGroup has one block to start.
        //This block is updated on disk by this call.
        BlockGroup * CreateNew();

        static void Test(bool menu=true, const char *filename=NULL, int StartBlockNumber[]=NULL);

        static int TestBlockGroup (int startBlockNumber, FreeList *mother);

        static void Check(FreeList *mother);

        ~FreeList();
        
private:
    Block * masterBlock;
    unsigned int setPointer;
    unsigned int nextPointer;
    };
    

#endif
